<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jerry的奶茶愿望清单</title>
    <!-- Bootstrap 5 CSS CDN -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: rgb(249, 211, 227);
            --secondary-color: rgb(255, 230, 240);
            --accent-color: rgb(218, 150, 182);
            --dark-pink: rgb(204, 120, 166);
            --light-brown: rgb(240, 203, 170);
            --tea-green: rgb(181, 218, 197);
            
            --primary-gradient: linear-gradient(135deg, var(--primary-color), var(--accent-color));
            --primary-gradient-hover: linear-gradient(135deg, var(--accent-color), var(--dark-pink));
            --card-bg: rgba(255, 255, 255, 0.95);
            --text-primary: #5a3d4c;
            --text-secondary: #8c6b7b;
            --success-color: #9fc6a9;
            --warning-color: #f9d3a0;
            --danger-color: #e8a6a6;
            --info-color: #a9c8e0;
            --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        body {
            background: var(--primary-gradient);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            min-height: 100vh;
            padding: 20px;
            background-attachment: fixed;
            background-size: 300% 300%;
            animation: gradientBG 15s ease infinite;
        }

        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .bubble {
            position: absolute;
            background: rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            z-index: -1;
        }

        .todo-app {
            background: var(--card-bg);
            border-radius: 20px;
            box-shadow: var(--shadow);
            overflow: hidden;
            position: relative;
            max-width: 800px;
            margin: 40px auto;
            transition: var(--transition);
            border: 1px solid rgba(255, 255, 255, 0.3);
            background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23f9d3e3' fill-opacity='0.2' fill-rule='evenodd'/%3E%3C/svg%3E");
        }

        .app-header {
            background: var(--primary-gradient);
            color: white;
            padding: 25px 0;
            text-align: center;
            position: relative;
            overflow: hidden;
            border-bottom: 3px solid var(--light-brown);
        }

        .app-header::before {
            content: "";
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0) 70%);
            transform: rotate(30deg);
        }

        .app-title {
            font-size: 2.5rem;
            font-weight: 700;
            margin: 0;
            position: relative;
            text-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }

        .app-subtitle {
            font-size: 1rem;
            opacity: 0.9;
            margin-top: 5px;
            position: relative;
        }

        .todo-form {
            padding: 20px;
            background: rgba(245, 245, 245, 0.7);
            border-bottom: 1px solid rgba(0,0,0,0.05);
        }

        .input-group {
            border-radius: 50px;
            overflow: hidden;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
            transition: var(--transition);
            border: 2px solid var(--light-brown);
        }

        .input-group:hover {
            box-shadow: 0 6px 15px rgba(0,0,0,0.15);
            transform: translateY(-2px);
        }

        .todo-input {
            border: none;
            padding: 15px 25px;
            font-size: 1.1rem;
            background: white;
            color: var(--text-primary);
        }

        .todo-input:focus {
            box-shadow: none;
            outline: none;
            border-color: var(--accent-color);
        }

        .todo-button {
            background: var(--primary-gradient);
            border: none;
            color: white;
            font-weight: 600;
            padding: 15px 30px;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .todo-button:hover {
            background: var(--primary-gradient-hover);
        }

        .todo-button:active {
            transform: scale(0.98);
        }

        .todo-stats {
            display: flex;
            justify-content: space-between;
            padding: 15px 25px;
            background: rgba(236, 240, 241, 0.7);
            font-size: 0.9rem;
            color: var(--text-secondary);
            border-bottom: 1px solid rgba(0,0,0,0.05);
        }

        .stat-item {
            display: flex;
            align-items: center;
            gap: 5px;
            background: var(--secondary-color);
            padding: 8px 15px;
            border-radius: 20px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }

        .todo-list {
            padding: 15px 0;
            min-height: 300px;
        }

        .task-item {
            display: flex;
            align-items: center;
            padding: 15px 25px;
            margin: 10px 20px;
            background: white;
            border-radius: 15px;
            box-shadow: 0 3px 10px rgba(0,0,0,0.05);
            transition: var(--transition);
            cursor: pointer;
            border-left: 4px solid var(--accent-color);
            animation: fadeIn 0.4s ease-out;
            position: relative;
            overflow: hidden;
        }

        .task-item::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(249, 211, 227, 0.1), transparent);
            z-index: 0;
            opacity: 0;
            transition: var(--transition);
        }

        .task-item:hover::before {
            opacity: 1;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .task-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.08);
            border-left-color: var(--dark-pink);
        }

        .task-item.completed {
            border-left-color: var(--tea-green);
            opacity: 0.9;
        }

        .task-checkbox {
            width: 28px;
            height: 28px;
            margin-right: 15px;
            cursor: pointer;
            border-radius: 50%;
            border: 2px solid var(--light-brown);
            display: flex;
            align-items: center;
            justify-content: center;
            transition: var(--transition);
            position: relative;
            z-index: 1;
        }

        .task-checkbox.checked {
            background: var(--tea-green);
            border-color: var(--tea-green);
        }

        .task-checkbox.checked::after {
            content: "✓";
            color: white;
            font-size: 16px;
            font-weight: bold;
        }

        .task-name {
            flex-grow: 1;
            font-size: 1.1rem;
            color: var(--text-primary);
            transition: var(--transition);
            position: relative;
            z-index: 1;
            padding: 5px 0;
        }

        .task-item.completed .task-name {
            text-decoration: line-through;
            color: var(--text-secondary);
        }

        .task-delete {
            color: var(--danger-color);
            opacity: 0.7;
            width: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            transition: var(--transition);
            font-size: 1.2rem;
            position: relative;
            z-index: 1;
        }

        .task-delete:hover {
            background: rgba(231, 76, 60, 0.1);
            opacity: 1;
            transform: scale(1.1);
            color: var(--dark-pink);
        }

        .empty-state {
            text-align: center;
            padding: 40px 20px;
            color: var(--text-secondary);
        }

        .empty-icon {
            font-size: 4rem;
            color: rgba(127, 140, 141, 0.3);
            margin-bottom: 20px;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.1); }
            100% { transform: scale(1); }
        }

        .empty-text {
            font-size: 1.2rem;
            margin-bottom: 20px;
        }

        .app-footer {
            padding: 20px;
            display: flex;
            justify-content: center;
        }

        .delete-all-btn {
            background: linear-gradient(135deg, var(--danger-color), #e8a6a6);
            border: none;
            padding: 12px 30px;
            border-radius: 50px;
            color: white;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
            box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
            transition: var(--transition);
        }

        .delete-all-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
        }

        .alert-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
            max-width: 350px;
        }

        .custom-alert {
            border-radius: 15px;
            border: none;
            box-shadow: 0 5px 15px rgba(0,0,0,0.15);
            padding: 15px 20px;
            color: white;
            display: flex;
            align-items: center;
            gap: 15px;
            animation: slideIn 0.5s ease, fadeOut 0.5s ease 2.5s forwards;
            position: relative;
            overflow: hidden;
        }

        @keyframes slideIn {
            from { transform: translateX(100%); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }

        @keyframes fadeOut {
            from { opacity: 1; }
            to { opacity: 0; }
        }

        .custom-alert::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 8px;
            height: 100%;
        }

        .alert-success {
            background: linear-gradient(135deg, var(--tea-green), #9fc6a9);
        }

        .alert-success::before {
            background: #9fc6a9;
        }

        .alert-danger {
            background: linear-gradient(135deg, var(--danger-color), #e8a6a6);
        }

        .alert-danger::before {
            background: #e8a6a6;
        }

        .alert-warning {
            background: linear-gradient(135deg, var(--warning-color), #f9d3a0);
        }

        .alert-warning::before {
            background: #f9d3a0;
        }

        .alert-info {
            background: linear-gradient(135deg, var(--info-color), #a9c8e0);
        }

        .alert-info::before {
            background: #a9c8e0;
        }

        .alert-icon {
            font-size: 1.5rem;
        }

        .loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.9);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            border-radius: 20px;
        }

        .spinner {
            width: 60px;
            height: 60px;
            border: 5px solid rgba(218, 150, 182, 0.2);
            border-top: 5px solid var(--accent-color);
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin-bottom: 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .loading-text {
            font-size: 1.2rem;
            color: #5a3d4c;
            font-weight: 500;
        }

        /* 奶茶相关装饰 */
        .milk-tea-decoration {
            position: absolute;
            font-size: 1.5rem;
            opacity: 0.3;
            z-index: 0;
        }
        
        .milk-tea-1 { top: 10%; left: 5%; animation: float 8s infinite ease-in-out; }
        .milk-tea-2 { top: 20%; right: 7%; animation: float 10s infinite ease-in-out; }
        .milk-tea-3 { bottom: 15%; left: 8%; animation: float 12s infinite ease-in-out; }
        
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-20px); }
            100% { transform: translateY(0px); }
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .todo-app {
                margin: 20px 10px;
            }
            
            .app-title {
                font-size: 2rem;
            }
            
            .todo-input {
                padding: 12px 20px;
            }
            
            .todo-button {
                padding: 12px 20px;
            }
            
            .task-item {
                padding: 12px 15px;
                margin: 8px 10px;
            }
        }
    </style>
</head>

<body>
    <!-- 装饰性奶茶图标 -->
    <div class="milk-tea-decoration milk-tea-1">
        <i class="fas fa-mug-hot"></i>
    </div>
    <div class="milk-tea-decoration milk-tea-2">
        <i class="fas fa-coffee"></i>
    </div>
    <div class="milk-tea-decoration milk-tea-3">
        <i class="fas fa-stroopwafel"></i>
    </div>
    
    <div class="todo-app">
        <div class="loading-overlay" style="display: none;">
            <div class="spinner"></div>
            <div class="loading-text">正在加载奶茶愿望...</div>
        </div>

        <div class="app-header">
            <h1 class="app-title"><i class="fas fa-mug-hot me-2"></i>Jerry的奶茶愿望清单</h1>
            <p class="app-subtitle">记录你想喝的奶茶，一起实现奶茶自由</p>
        </div>

        <div class="todo-form">
            <div class="input-group">
                <input type="text" class="form-control todo-input" placeholder="添加一杯想喝的奶茶...">
                <button class="btn todo-button" type="button">
                    <i class="fas fa-plus"></i> 添加
                </button>
            </div>
        </div>

        <div class="todo-stats">
            <div class="stat-item">
                <i class="fas fa-mug-hot"></i>
                <span>奶茶总数: <span id="totalTasks">0</span></span>
            </div>
            <div class="stat-item">
                <i class="fas fa-check-circle"></i>
                <span>已喝到: <span id="completedTasks">0</span></span>
            </div>
        </div>

        <div class="todo-list">
            <div class="empty-state">
                <div class="empty-icon">
                    <i class="fas fa-mug-hot"></i>
                </div>
                <h3 class="empty-text">当前没有奶茶愿望</h3>
                <p>添加您的第一杯奶茶吧！</p>
            </div>
            <!-- 任务将通过JS动态添加 -->
        </div>

        <div class="app-footer">
            <button id="deleteAllBtn" class="btn delete-all-btn" >
                <i class="fas fa-trash-alt"></i> 一键删除所有奶茶愿望
            </button>
        </div>
    </div>

    <!-- 警告提示框容器 -->
    <div class="alert-container" id="alertContainer"></div>

    <!-- 确认删除模态框 -->
    <div class="modal fade" id="confirmDeleteModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">确认操作</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="text-center mb-4">
                        <i class="fas fa-exclamation-triangle text-danger" style="font-size: 3rem;"></i>
                    </div>
                    <p class="text-center">确定要删除所有奶茶愿望吗？此操作不可撤销！</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-danger" id="confirmDeleteAll">
                        <i class="fas fa-trash me-1"></i> 确认删除
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- 脚本依赖 -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

    <script>
        $(document).ready(function () {
            // 初始化变量
            const todoList = $('.todo-list');
            const emptyState = $('.empty-state');
            const loadingOverlay = $('.loading-overlay');
            
            // 页面加载完成后自动获取数据
            getList();
            
            // 为添加按钮绑定点击事件
            $('.todo-button').click(addTodoItem);
            
            // 为输入框绑定回车键事件
            $('.todo-input').keypress(function (e) {
                if (e.which == 13) addTodoItem();
            });
            
            // 获取数据库中的任务列表
            async function getList() {
                loadingOverlay.show();
                
                try {
                    const res = await axios({
                        url: "https://sr3enbjw6p.hzh.sealos.run/get-todos",
                        method: "get",
                    });
                    
                    const data = res.data;
                    todoList.empty();
                    
                    if (data && data.data && data.data.todos && Array.isArray(data.data.todos)) {
                        // 更新任务统计
                        updateTaskStats(data.data.todos);
                        
                        if (data.data.todos.length > 0) {
                            emptyState.hide();
                            $('#deleteAllBtn').show();
                            
                            data.data.todos.forEach(todo => {
                                const isCompleted = todo.completed || false;
                                const todoText = todo.text || todo.title || todo.name || '';
                                
                                if (todoText) {
                                    const taskItem = createTaskElement(todoText, isCompleted, todo._id || todo.id);
                                    todoList.append(taskItem);
                                }
                            });
                            
                            showAlert('奶茶愿望加载成功！共加载 ' + data.data.todos.length + ' 个愿望', 'success');
                        } else {
                            showEmptyState();
                        }
                    } else {
                        showAlert('未找到奶茶愿望数据', 'info');
                        showEmptyState();
                    }
                } catch (error) {
                    console.error('获取奶茶愿望列表失败:', error);
                    showAlert('获取奶茶愿望失败,请检查网络连接!', 'danger');
                    showEmptyState();
                } finally {
                    loadingOverlay.hide();
                }
            }
            
            // 创建任务元素
            function createTaskElement(text, isCompleted, id) {
                const taskItem = $(`
                    <div class="task-item ${isCompleted ? 'completed' : ''}" data-todo-id="${id}">
                        <div class="task-checkbox ${isCompleted ? 'checked' : ''}"></div>
                        <div class="task-name">${text}</div>
                        <div class="task-delete">
                            <i class="fas fa-times"></i>
                        </div>
                    </div>
                `);
                
                // 复选框点击事件
                taskItem.find('.task-checkbox').click(async function() {
                    const $item = $(this).closest('.task-item');
                    const todoId = $item.data('todo-id');
                    
                    // 更新UI
                    $(this).toggleClass('checked');
                    $item.toggleClass('completed', $(this).hasClass('checked'));
                    
                    // 更新任务统计
                    updateTaskStats();
                    
                    try {
                        await updateTodo(todoId);
                        showAlert('奶茶愿望状态已更新！', 'success');
                    } catch (error) {
                        // 失败时回滚UI状态
                        $(this).toggleClass('checked');
                        $item.toggleClass('completed');
                        updateTaskStats();
                        showAlert('更新奶茶愿望状态失败', 'danger');
                    }
                });
                
                // 删除按钮点击事件
                taskItem.find('.task-delete').click(async function() {
                    const $item = $(this).closest('.task-item');
                    const todoId = $item.data('todo-id');
                    
                    // 添加删除动画
                    $item.css('transform', 'translateX(100%)');
                    $item.css('opacity', '0');
                    
                    setTimeout(async () => {
                        try {
                            await deleteTodo(todoId);
                            $item.remove();
                            updateTaskStats();
                            
                            // 检查是否还有任务
                            if ($('.task-item').length === 0) {
                                showEmptyState();
                            }
                            
                            showAlert('奶茶愿望已删除！', 'success');
                        } catch (error) {
                            // 失败时恢复元素
                            $item.css('transform', '');
                            $item.css('opacity', '');
                            showAlert('删除奶茶愿望失败', 'danger');
                        }
                    }, 300);
                });
                
                return taskItem;
            }
            
            // 显示空状态
            function showEmptyState() {
                todoList.empty().append(emptyState.show());
                $('#totalTasks').text('0');
                $('#completedTasks').text('0');
                $('#deleteAllBtn').hide();
            }
            
            // 更新任务统计
            function updateTaskStats(tasks) {
                if (!tasks) {
                    tasks = $('.task-item');
                }
                
                const total = tasks.length;
                const completed = tasks.filter((i, el) => $(el).hasClass('completed')).length;
                
                $('#totalTasks').text(total);
                $('#completedTasks').text(completed);
            }
            
            // 添加新任务
            async function addTodoItem() {
                const todoText = $('.todo-input').val().trim();
                $('#deleteAllBtn').show();
                
                if (todoText === '') {
                    showAlert('请输入奶茶愿望内容！', 'warning');
                    // 输入框抖动效果
                    $('.todo-input').css('animation', 'shake 0.5s');
                    setTimeout(() => $('.todo-input').css('animation', ''), 500);
                    return;
                }
                
                // 显示加载状态
                const addButton = $('.todo-button');
                addButton.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 添加中...');
                
                try {
                    // 调用后端API添加任务
                    const result = await axios({
                        url: "https://sr3enbjw6p.hzh.sealos.run/add-todo",
                        method: "post",
                        data: { text: todoText, isComplete: false }
                    });
                    
                    if (result.data && result.data.code === 200) {
                        // 创建新任务元素
                        const taskId = result.data.data.id || Date.now(); // 假设返回了ID
                        const taskItem = createTaskElement(todoText, false, taskId);
                        
                        // 隐藏空状态（如果存在）
                        emptyState.hide();
                        
                        // 添加新任务并带有动画
                        taskItem.css('opacity', 0);
                        todoList.prepend(taskItem);
                        taskItem.animate({ opacity: 1 }, 300);
                        
                        // 清空输入框
                        $('.todo-input').val('');
                        
                        // 更新任务统计
                        updateTaskStats();
                        
                        showAlert('奶茶愿望添加成功！', 'success');
                    } else {
                        showAlert('添加奶茶愿望失败：' + (result.data?.message || '未知错误'), 'danger');
                    }
                } catch (error) {
                    console.error('添加奶茶愿望出错:', error);
                    showAlert('添加奶茶愿望失败，请重试！', 'danger');
                } finally {
                    // 恢复按钮状态
                    addButton.prop('disabled', false).html('<i class="fas fa-plus"></i> 添加');
                }
            }
            
            // 更新任务状态
            async function updateTodo(id) {
                try {
                    await axios({
                        url: "https://sr3enbjw6p.hzh.sealos.run/updata-todo",
                        method: "post",
                        data: { id }
                    });
                } catch (error) {
                    console.error('修改奶茶愿望失败:', error);
                    throw error;
                }
            }
            
            // 删除任务
            async function deleteTodo(id) {
                try {
                    await axios({
                        url: "https://sr3enbjw6p.hzh.sealos.run/delet",
                        method: "delete",
                        data: { id }
                    });
                } catch (error) {
                    console.error('删除奶茶愿望失败:', error);
                    throw error;
                }
            }
            
            // 显示警告提示
            function showAlert(message, type) {
                const alertContainer = $('#alertContainer');
                const alertClass = `custom-alert alert-${type}`;
                
                const alertBox = $(`
                    <div class="${alertClass}">
                        <div class="alert-icon">
                            ${type === 'success' ? '<i class="fas fa-check-circle"></i>' : 
                              type === 'danger' ? '<i class="fas fa-exclamation-circle"></i>' : 
                              type === 'warning' ? '<i class="fas fa-exclamation-triangle"></i>' : 
                              '<i class="fas fa-info-circle"></i>'}
                        </div>
                        <div class="alert-message">${message}</div>
                    </div>
                `);
                
                alertContainer.append(alertBox);
                
                // 5秒后移除提示
                setTimeout(() => {
                    alertBox.animate({ opacity: 0 }, 300, function() {
                        $(this).remove();
                    });
                }, 3000);
            }
            
            // 一键删除所有任务
            async function deleteAllTodos(ids) {
                if (ids.length === 0) {
                    showAlert('没有奶茶愿望可删除', 'info');
                    return;
                }
                
                loadingOverlay.show().find('.loading-text').text('正在删除所有奶茶愿望...');
                
                try {
                    // 模拟删除动画
                    $('.task-item').each(function(index) {
                        $(this).delay(100 * index).animate({
                            opacity: 0,
                            height: 0,
                            paddingTop: 0,
                            paddingBottom: 0,
                            marginTop: 0,
                            marginBottom: 0
                        }, 300, function() {
                            $(this).remove();
                        });
                    });
                    
                    // 实际删除操作
                    await axios({
                        url: "https://sr3enbjw6p.hzh.sealos.run/delete-all",
                        method: "delete",
                        data: { ids }
                    });
                    
                    showAlert('所有奶茶愿望已成功删除', 'success');
                    showEmptyState();
                } catch (error) {
                    console.error('删除所有奶茶愿望失败:', error);
                    showAlert('删除失败: ' + (error.response?.data?.message || '网络连接异常'), 'danger');
                } finally {
                    loadingOverlay.hide();
                    $('#confirmDeleteModal').modal('hide');
                }
            }
            
            // 获取所有任务ID
            function getAllIds() {
                return $('.task-item').map(function() {
                    return $(this).data('todo-id');
                }).get();
            }
            
            // 一键删除按钮事件
            $('#deleteAllBtn').click(function() {
                if ($('.task-item').length > 0) {
                    $('#confirmDeleteModal').modal('show');
                    $('#deleteAllBtn').show();

                } else {
                    $('#deleteAllBtn').hide();
                    showAlert('当前没有奶茶愿望可删除！', 'warning');
                }
            });

         
            
            // 确认删除按钮事件
            $('#confirmDeleteAll').click(function() {
                const $btn = $(this);
                $btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin me-1"></i> 删除中...');
                
                const ids = getAllIds();
                deleteAllTodos(ids);
                
                setTimeout(() => $btn.prop('disabled', false).html('<i class="fas fa-trash me-1"></i> 确认删除'), 2000);
            });
        });
    </script>
</body>
</html>